package com.study.dao.impl;

import com.study.bean.query.BuildingQuery;
import com.study.service.impl.BuilDao;
import com.study.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class BuilDaoImpl implements BuilDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    @Override
    public List<BuildingQuery> selecByPage(BuildingQuery buildingQuery) {
        String sql = "select db.*,da.m_name from dormitory_buildings db left join dormitory_admins da on db.administrator_id = da.admin_id  limit ?,?";
        int offSet = (buildingQuery.getPage()-1) * buildingQuery.getLimit();
        int  limitq = buildingQuery.getLimit();
        List<BuildingQuery> query = template.query(sql, new BeanPropertyRowMapper<>(BuildingQuery.class) ,offSet, limitq);
        return query;
    }
}
